package org.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import org.dk.domain.DataResult;
import org.dk.em.DataResultEnum;
import org.dk.pageInfo.PageInfo2;
import org.dk.pojo.TbSeller;
import org.dk.service.SellerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("seller")
public class SellerController {


    @Reference
    private SellerService sellerService;

    @RequestMapping("selectSeller")
    @ResponseBody
    public DataResult selectSeller(@RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize, String name, String nickName) {

        try {
            PageInfo2 page = sellerService.selectSeller(pageNum,pageSize,name,nickName);
            return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(page);
        } catch (Exception e){
            return DataResult.buildDataResult(DataResultEnum.ERROR);
        }
    }


    @RequestMapping("selectById")
     @ResponseBody
     public DataResult selectById(String sellerId){
         try {
             TbSeller page = sellerService.selectById(sellerId);
             return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(page);
         } catch (Exception e){
             return DataResult.buildDataResult(DataResultEnum.ERROR);
         }
     }

    @RequestMapping("updateSeller")
    @ResponseBody
    public DataResult updateSeller(TbSeller seller){
        try {
            sellerService.updateSeller(seller);
            return DataResult.buildDataResult(DataResultEnum.SUCCESS);
        } catch (Exception e){
            return DataResult.buildDataResult(DataResultEnum.ERROR);
        }
    }

    @RequestMapping("seller")
    public String seller(){
        return "admin/seller_1";
    }
}
